package com.liuwang.meal.manager;

//菜谱管理类
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.liuwang.meal.bean.MenuType;
import com.liuwang.meal.db.DBHelper;
import com.liuwang.meal.db.MenuTypes;

public class MenuTypeManager {
	private Context context = null;

	public MenuTypeManager(Context context) {
		this.context = context;
	}
	
	// 按照所有菜谱类型
	public List<MenuType> queryMenuTypes(){
		// 获取数据库
		DBHelper db = new DBHelper(this.context);
		SQLiteDatabase database = db.getReadableDatabase();
		String sql = "select _id,name from "+MenuTypes.TABLE;
     	// 执行语句
    	Cursor  cursor = database.rawQuery(sql,null);
    	// 循环遍历结果集
    	List<MenuType>  list = new ArrayList<MenuType>();

    	while(cursor.moveToNext()){
    		Integer _id = cursor.getInt(cursor.getColumnIndex("_id"));
    		String name = cursor.getString(cursor.getColumnIndex("name"));
    		MenuType menuType = new MenuType(_id,name);
    	    list.add(menuType);
    	}

    	// 关闭数据库
    	database.close();
    	return list;
	}
}
